﻿using System;
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using Gameplay.RTS.ScriptConfig;
using UnityEngine;
using UnityEngine.Profiling;
using Yoozoo.Gameplay.RTS;
using Yoozoo.Gta.Common;
using Random = UnityEngine.Random;

public enum GpuFlyTextAnim
{
    None = 0,
    Left = 1, 
    Right = 2, 
    IntoUp = 3, 
    IntoInto = 4, 
    SkillLeft = 5, 
    SkillRight = 6, 
    IntoIntoHeal = 7, 
    IntoUpIcon = 8
}


public static class GpuFlyTextHelper
{
    public static HashSet<int> FlyTextIdList;
    public static int MaxShowNum = 2000;
    public static float frameTime = 0.033f;
    //统一缩放系数(根据FlyTextManager的FlyTextRoot来确定)
    public static float commonScaleFactory = 0.03f;
    

    public static bool PlayFlyText(int id, Vector3 initPos, float duration, string content)
    {
        
        if (FlyTextIdList == null)
        {
            FlyTextIdList = new HashSet<int>();
            ResidentHandler.Inst.GetFunction("L_GpuHudLuaFunction.GetAllFlyTextIdList").Action<Action<List<int>>>((List<int> list) =>
            {
                for (int i = 0; i < list.Count; ++i)
                {
                    FlyTextIdList.Add(list[i]);
                }
            });
        }

        if (FlyTextIdList.Contains(id))
        {
            Profiler.BeginSample("GpuFlyText_Begin");
            
            var textOffsetConfig = ArmyManager.Instance.ResourceManager.JsonManager.GetFlyTextOffsetByType(id);
            if (textOffsetConfig!=null)
            {
                var offset = new Vector3(textOffsetConfig.x, textOffsetConfig.y, textOffsetConfig.z);
                if (textOffsetConfig.isRandom)
                {
                    offset = offset + RandomSkillOffset(textOffsetConfig);
                }
                initPos = initPos + offset;
            }
            
            GpuFlyTextEntity nf =  GpuHudEntityHelper.PlayFlyText(id, initPos, duration, content);
            Profiler.EndSample();
            if (nf!=null)
            {
                return true;
            }
        }
  
        return false;
    }
    public static Vector3 RandomSkillOffset(FlyTextOffset textOffsetConfig)
    {
        var ratio = Random.Range(0, 10) > 5 ? 1 : -1;
        var offsetx = Random.Range(textOffsetConfig.randomXmin, textOffsetConfig.randomXmax) * ratio;
        var offsety = Random.Range(textOffsetConfig.randomYmin, textOffsetConfig.randomYmax);
        return new Vector3(offsetx, offsety, 0);
    }

    
    
}
